const wechatSerivce = think.service('wechat'),
	tokenService = think.service('token'),
	errorInfo = require('../config/error-info');

module.exports = class extends think.Controller {
	/*async __before() {
		let controller = this.ctx.controller,
			action = this.ctx.action,
			receivedToken = this.header('token'),
			tokenResult = await tokenService.verifyToken(receivedToken),
			cacheToken = receivedToken ? await this.cache(`token-${tokenResult.data.account}`) : null,
			sessionAuth = await this.session('auth'),
			sessionParse = await tokenService.verifyToken(sessionAuth),
			sessionCacheToken = sessionAuth ? await this.cache(`token-${sessionParse.data.account}`) : null;

		if (controller === 'auth' && action === 'login') {
			let account = this.post('account'),
				token = tokenService.createToken({account});
			//重复登录
			if(sessionCacheToken && sessionAuth === sessionCacheToken) return this.fail(...errorInfo.msg1004);
			//异终端登录
			if(sessionCacheToken && sessionAuth !== sessionCacheToken) return this.fail(...errorInfo.msg1003);

			this.ctx.state.token = token;
		} else {
			// 请求头中没有提供token参数
			if (!receivedToken) return this.fail(...errorInfo.msg1005,'the token of request header is void');
			//session无效,
			if(!sessionParse) return this.fail(...errorInfo.msg1007);
			// token校验异常
			if (tokenResult.error) return this.fail(...errorInfo.msg1002,tokenResult.msg);
			// token过期
			if(!cacheToken) return this.fail(...errorInfo.msg1006);
			// 上下文中保存当前请求对应的用户信息
			this.ctx.state.currentUser = tokenResult.data;
		}
	}*/
};
